﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;
using KaoQin.DBUtility;//Please add references
namespace KaoQin.DAL
{
    /// <summary>
    /// 数据访问类:ICCardManager
    /// </summary>
    public partial class ICCardManager
    {
        public ICCardManager()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ICCardManager");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50)			};
            parameters[0].Value = ID;

            return SQLiteHelper.Exists(strSql.ToString(), parameters);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(KaoQin.Model.ICCardManagerInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ICCardManager(");
            strSql.Append("ID,ICCardID,EmployeeID,KState,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("@ID,@ICCardID,@EmployeeID,@KState,@CreateTime)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50),
					new SQLiteParameter("@ICCardID", DbType.String,50),
					new SQLiteParameter("@EmployeeID", DbType.String,50),
					new SQLiteParameter("@KState", DbType.Int32,4),
					new SQLiteParameter("@CreateTime", DbType.DateTime)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.ICCardID;
            parameters[2].Value = model.EmployeeID;
            parameters[3].Value = model.KState;
            parameters[4].Value = model.CreateTime;

            int rows = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(KaoQin.Model.ICCardManagerInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ICCardManager set ");
            strSql.Append("ICCardID=@ICCardID,");
            strSql.Append("EmployeeID=@EmployeeID,");
            strSql.Append("KState=@KState,");
            strSql.Append("CreateTime=@CreateTime");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ICCardID", DbType.String,50),
					new SQLiteParameter("@EmployeeID", DbType.String,50),
					new SQLiteParameter("@KState", DbType.Int32,4),
					new SQLiteParameter("@CreateTime", DbType.DateTime),
					new SQLiteParameter("@ID", DbType.String,50)};
            parameters[0].Value = model.ICCardID;
            parameters[1].Value = model.EmployeeID;
            parameters[2].Value = model.KState;
            parameters[3].Value = model.CreateTime;
            parameters[4].Value = model.ID;

            int rows = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ICCardManager ");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50)			};
            parameters[0].Value = ID;

            int rows = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ICCardManager ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = SQLiteHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KaoQin.Model.ICCardManagerInfo GetModel(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,ICCardID,EmployeeID,KState,CreateTime from ICCardManager ");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50)			};
            parameters[0].Value = ID;

            KaoQin.Model.ICCardManagerInfo model = new KaoQin.Model.ICCardManagerInfo();
            DataSet ds = SQLiteHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KaoQin.Model.ICCardManagerInfo DataRowToModel(DataRow row)
        {
            KaoQin.Model.ICCardManagerInfo model = new KaoQin.Model.ICCardManagerInfo();
            if (row != null)
            {
                if (row["ID"] != null)
                {
                    model.ID = row["ID"].ToString();
                }
                if (row["ICCardID"] != null)
                {
                    model.ICCardID = row["ICCardID"].ToString();
                }
                if (row["EmployeeID"] != null)
                {
                    model.EmployeeID = row["EmployeeID"].ToString();
                }
                if (row["KState"] != null && row["KState"].ToString() != "")
                {
                    model.KState = int.Parse(row["KState"].ToString());
                }
                if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,ICCardID,EmployeeID,KState,CreateTime ");
            strSql.Append(" FROM ICCardManager ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLiteHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM ICCardManager ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = SQLiteHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int currentIndex, int pageSize, out int recordCount)
        {
            return SQLiteHelper.Query("ICCardManager", "*", strWhere, orderby, pageSize, currentIndex, out recordCount);
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@tblName", DbType.VarChar, 255),
                    new SQLiteParameter("@fldName", DbType.VarChar, 255),
                    new SQLiteParameter("@PageSize", DbType.Int32),
                    new SQLiteParameter("@PageIndex", DbType.Int32),
                    new SQLiteParameter("@IsReCount", DbType.bit),
                    new SQLiteParameter("@OrderType", DbType.bit),
                    new SQLiteParameter("@strWhere", DbType.VarChar,1000),
                    };
            parameters[0].Value = "ICCardManager";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return SQLiteHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

